home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 43.3 KB | 1,079 lines | [TEXT/MPS ] |
- // UDispatcher.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UDISPATCHER__
- #define __UDISPATCHER__
-
- // MacApp
-
- #ifndef __GEOMETRY__
- #include "Geometry.h"
- #endif
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- #ifndef __UBEHAVIOR__
- #include "UBehavior.h"
- #endif
-
- #ifndef __UCOMMANDHANDLER__
- #include "UCommandHandler.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __ULISTITERATOR__
- #include "UListIterator.h"
- #endif
-
- #ifndef __USCRIPTABLEOBJECT__
- #include "UScriptableObject.h"
- #endif
-
- // CALib
-
- #if qContainer
- #ifndef _CALIB_
- #include "CALib.h"
- #endif
- #endif
-
- // Toolbox
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // Performance monitor menu command constants used by TDispatcher.
- //----------------------------------------------------------------------------------------
-
- // const CommandNumber cPerfMonInit = 901;
- // const CommandNumber cPerfMonDump = 902;
- // const CommandNumber cPerfMonToggle = 903;
- // const CommandNumber cPerfMonEnd = 904;
-
-
- //----------------------------------------------------------------------------------------
- // Debugger menu command constants used by TDispatcher.
- //----------------------------------------------------------------------------------------
-
- // const CommandNumber cDebugFlags = 913;
- // const CommandNumber cDoFirstClick = 915; // <!> Toggle. "'Do First Click' for this
- // const CommandNumber cRefreshFrontWindow = 917; // <!> Action. "Refresh Front Window"
- // const CommandNumber cSetSysJust = 921; // <!> Action. "Switch system
- // justification"
-
- //----------------------------------------------------------------------------------------
- // Arguments of TDispatcher::GetActiveWindow
- //----------------------------------------------------------------------------------------
- const Boolean kFloatersOK = TRUE;
- const Boolean kNoFloaters = FALSE;
-
- //----------------------------------------------------------------------------------------
- // Timeout Argument of TDispatcher::InteractWithUser
- //----------------------------------------------------------------------------------------
-
- const long kMacAppTimeout = 901; // let MacApp decide how to handle the timeout
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- // struct StandardFileReply;
- class TDocument;
- #if qContainer
- class TFileBasedDocument;
- #endif
- class TEvent;
- class TDispatcher;
- class TFile;
- class TMenuBarManager;
- class TToolboxEvent;
- class TTracker;
- class TView;
- class TWindow;
-
-
- //----------------------------------------------------------------------------------------
- // CDocumentIterator
- //----------------------------------------------------------------------------------------
-
- class CDocumentIterator : public CObjectIterator
- {
- public:
- CDocumentIterator(const TDispatcher* itsApplication,
- ArrayIndex itsLowBound, ArrayIndex itsHighBound,
- Boolean itsForward);
-
- CDocumentIterator(const TDispatcher* itsApplication, Boolean itsForward);
-
- CDocumentIterator(const TDispatcher* itsApplication);
-
- virtual ~CDocumentIterator();
-
- inline TDocument* CurrentDocument()
- { return (TDocument *)this->CurrentObject(); }
- // returns the current document
-
- inline TDocument* FirstDocument()
- { return (TDocument *)this->FirstObject(); }
- // return the first document in the iteration
-
- inline TDocument* NextDocument()
- { return (TDocument *)this->NextObject(); }
- // advances the iteration and then returns the document
- };
-
- //----------------------------------------------------------------------------------------
- // CNoGhostDocsIterator
- //----------------------------------------------------------------------------------------
-
- class CNoGhostDocsIterator : public CDocumentIterator
- {
- public:
- inline CNoGhostDocsIterator(const TDispatcher* itsApplication,
- ArrayIndex itsLowBound, ArrayIndex itsHighBound,
- Boolean itsForward) :
- CDocumentIterator(itsApplication, itsLowBound, itsHighBound, itsForward)
- { }
-
- inline CNoGhostDocsIterator(const TDispatcher* itsApplication, Boolean itsForward) :
- CDocumentIterator(itsApplication, itsForward)
- { }
-
- inline CNoGhostDocsIterator(const TDispatcher* itsApplication) :
- CDocumentIterator(itsApplication)
- { }
-
- virtual ~CNoGhostDocsIterator();
-
- virtual Boolean More();
- };
-
- #if qContainer
-
- //----------------------------------------------------------------------------------------
- // CCADocumentIterator -- iterate over container documents
- //----------------------------------------------------------------------------------------
-
- class CCADocumentIterator : public CObjectIterator
- {
- public:
- CCADocumentIterator(const TDispatcher* itsApplication,
- ArrayIndex itsLowBound, ArrayIndex itsHighBound,
- Boolean itsForward);
-
- CCADocumentIterator(const TDispatcher* itsApplication, Boolean itsForward);
-
- CCADocumentIterator(const TDispatcher* itsApplication);
-
- virtual ~CCADocumentIterator();
-
- inline TFileBasedDocument* CurrentDocument()
- { return (TFileBasedDocument *)this->CurrentObject(); }
-
- inline TFileBasedDocument* FirstDocument()
- { return (TFileBasedDocument *)this->FirstObject(); }
-
- inline TFileBasedDocument* NextDocument()
- { return (TFileBasedDocument *)this->NextObject(); }
- };
-
- #endif
- //----------------------------------------------------------------------------------------
- // TEventList: A list for keeping TEvents ordered by priority
- //----------------------------------------------------------------------------------------
-
- class TEventList : public TSortedList
- {
- MA_DECLARE_CLASS;
-
- public:
- TEventList();
- // Empty constructor to satisfy compiler.
- virtual ~TEventList();
- // Destructor
-
- void IEventList();
- // Initialize the EventList procedurally.
-
- virtual CompareResult Compare(TObject* item1,
- TObject* item2);
- // Compares Two TEvents based on their priority
-
- virtual void Insert(TObject* item);
- // Overridden to guarantee insertion even in low memory and to preserve arrival
- // sequence within "Compare" ordering.
-
- };
-
- //----------------------------------------------------------------------------------------
- // TDispatcher: The purpose of this class is to implement the main event loop that all
- // Macintosh applications must have. There is only one instance of TDispatcher. One thing
- // that TDispatcher does is to interpret the raw events that are posted and convert them
- // into higher-level events. For example, it converts a click in the menu bar into a 'menu
- // event' that contains the menu ID/ item number that was chosen by the user.
- //----------------------------------------------------------------------------------------
-
- class TDispatcher : public TCommandHandler, public MDefaultScriptableObject
- {
- MA_DECLARE_CLASS;
-
- public:
- OSType fCreator; // The application signature; Creator type
- // for files. This is used by DoMakeFile.
-
- OSType fMainFileType; // principal file type opened/printed by
- // application; by default,
- // TDispatcher::SFGetFilters returns a
- // list of just this. Used by DoMakeFile
-
- TEventList* fEventList; // Events/Commands that were posted for
- // execution
-
-
- // Boolean fLaunchWithNewDocument; // True (the default) to create a new
- // untitled document when the application
- // is launched without a document.
-
- Boolean fAllowApplicationToSleep; // Whether the application should be
- // allowed to "sleep" and thus share
- // processor time, when getting events
-
- ProcessSerialNumber fProcessNumber; // This application's process serial
- // number.
-
- IdlePhase fIdlePhase; // The current idle phase
-
- Boolean fAlwaysTrackCursor; // set this to true when you want the
- // application to track the cursor even if
- // it doesn't stray outside gCursorRgn.
-
- Boolean fDone; // set this to true when you want the
- // application to terminate
-
- short fClickCount; // number of 'saved up' mouse clicks. If a
- // mouseDown, the value is that returned
- // by the call to
- // TDispatcher::CountClicks. If a mouseUp,
- // the value is left alone. Otherwise, set
- // to 0. Also set to 0 is the 2 clicks
- // were in different parts ofthe window.
-
- short fLastClickPart; // the list window part clicked in-used
- // for double click detection
-
- CPoint fLastMousePoint; // coordinates of mouse in last event
- // passed to TDispatcher.CountClicks
-
- long fLastUpTime; // time of last mouse up event
-
- long fNextSpaceMessage; // time when next low space message should
- // be displayed
-
- long fLowSpaceInterval; // If >= 0, the frequency (in Ticks) with
- // which MacApp displays a low space
- // alert. (Defaults to kLowSpaceInterval.)
- // If < 0, MacApp doesn't display an
- // alert.
-
- short fMainEventMask; // Event mask used in main event loop.
- // Initialized by InitUMacApp.
-
- Boolean fSysWindowActive; // True if the front window is a system
- // window
-
- // Boolean fUndoState; // are we in undo or redo
-
- CommandNumber fUndoCommand; // the command number currently in the undo menu
-
- CommandNumber fRedoCommand; // the command number currently in the redo menu
-
- TList* fDocumentList; // list of documents
-
- TList* fFreeWindowList; // list of free-standing (documentless)
- // windows
-
- TEventHandler* fHeadCohandler; // head of linked list of global
- // co-handlers
-
- TEventHandler* fTarget; // the TEventHandler that gets the first
- // chance at DoCommand, DoSetupMenu,
- // DoKeyEvent, Idle; should never be NULL
- // -- If you do not want your own target
- // set this to the application object
-
- short fEventLevel; // A count of the number of nested calls
- // to PollToolboxEvent.
-
- ResNumber fDisplayedMenus; // menus that are read in and installed in
- // menu bar
-
- ResNumber fMBarHierarchical; // menus that pop up when a menu item is
- // choosen
-
- ResNumber fOtherMenus; // menus that are read in but not
- // installed
-
- RgnHandle fSleepRegion; // the region that will be passed to
- // WaitNextEvent as the sleep region.
- // Computed from the cursor and help
- // regions
-
- RgnHandle fCursorRegion; // the current cursor region
-
- RgnHandle fHelpRegion; // the current help region
-
- Boolean fWantKeyUpEvents; // set this to true in your constructor to set
- // the system mask to allow key-up events
-
- // #if qDebug
- // TWindow* fDebugFlagsWindow; // Window for setting the debug flags
- // #endif
-
- //------------------------------------------------------------------------------------
- // Initialization and Free
- //------------------------------------------------------------------------------------
-
- TDispatcher();
- // Constructor
- virtual ~TDispatcher();
- // Destructor
-
- void IDispatcher(OSType itsMainFileType,
- OSType itsCreator);
- // itsMainFileType should be the 4-byte file type that this application reads and
- // writes. itsCreator is the application's signiture. They are used when creating
- // a default file with DoMakeFile and to display the proper file types in the
- // StandardFile dialogs.
-
- // virtual Boolean ChooseApplication(AEAddressDesc& theAddress);
- // Choose a running application using the PPCBrowser and store the address in an
- // AppleEvent address
-
- virtual TMenuBarManager* MakeMenuBarManager();
- // Creates an instance of TMenuBarManager
-
- //------------------------------------------------------------------------------------
- // Event Handling
- //------------------------------------------------------------------------------------
-
- virtual TToolboxEvent* GetEvent(short eventMask, long sleep,
- RgnHandle sleepRegion);
- // Calls WaitNextEvent (or GetNextEvent) with the given event mask, sleep, and
- // sleep region parameters. You can override this if you have an alternate source
- // for events.
-
- virtual void HandleAlienEvent(TToolboxEvent* event);
- // This method is called upon to deal with 'application-specific' events
-
- virtual void MainEventLoop();
- // Loop on PollEvent until the application is done
-
- virtual void DispatchEvent(TToolboxEvent* event);
-
- virtual void DoToolboxEvent(TToolboxEvent* event);
- // When this is called by MacApp, theEvent is the event to be processed.
-
- virtual void DidEvent(TToolboxEvent* event);
-
- // Added for 3.5
- virtual void DispatchMenuEvent(TToolboxEvent* event, long menuItem);
- // Handles menu events.
-
- virtual void HandleActivateEvent(TToolboxEvent* event);
- // Handles activate (and deactivate) events. Calls the window's Activate method,
- // and invalidates the menubar if activating the window.
-
- virtual void HandleDiskEvent(TToolboxEvent* event);
- // Handles disk events. Calls DIBadMount if the high word of theEvent's message is
- // <> noErr
-
- virtual void HandleHighLevelEvent(TToolboxEvent* event);
- // Process a high level event. Default behavior is to assume it is an AppleEvent.
-
- virtual void KeyEventToComponents(TToolboxEvent* event);
- // re-extracts components of an event in a script manager compatible way.
-
- virtual void HandleKeyDownEvent(TToolboxEvent* event);
- // Handles key down events. If the command key is down, then this calls
- // CommandKey. Otherwise it calls fTarget->DoKeyEvent.
-
- virtual void HandleKeyUpEvent(TToolboxEvent* event);
- // Handles key up events. Calls fTarget->DoKeyEvent.
-
- virtual void HandleMouseDown(TToolboxEvent* event);
- // Called when a mouse down occurs; this cases on whereMouseDown and does the
- // right thing.
-
- virtual TTracker* TrackMouse(const VPoint& theMouse, CPoint hysteresis,
- TTracker* theCommand);
- // Responsible for mouse tracking. !!! Candidate for eventhandler method?
-
- virtual void HandleMouseUp(TToolboxEvent* event);
- // Sets fLastUpTime.
-
- virtual void HandleSystemEvent(TToolboxEvent* event);
- // Handles "system" events, in particular suspend/ resume events and mouse moved
- // events. Calls RegainControl if switching in, AboutToLoseControl if switching
- // out, or TrackCursor if it is a mouse-moved event.
-
- virtual void HandleToolboxEvent(TToolboxEvent* event);
- // Handles the dispatching of DoToolboxEvent messages between itself and Behaviors.
-
- virtual void HandleUpdateEvent(TToolboxEvent* event);
- // Handles window update events. Calls UpdateEvent for the window indicate by the
- // event.
-
- Boolean IsFrontProcess();
- // Returns true if the application is currently the front process.
-
- virtual void MakeFrontProcess();
- // Makes this application the front process.
-
- virtual void WakeProcess();
- // Wakes this process if it is sleeping in WaitNextEvent. Used by callback
- // procs (drag manager, apple event manager) that get called when the
- // process is in a WaitNextEvent, to return from WNE and reevaluate the
- // internal command que.
-
- virtual void OpenDeskAccessory(const CStr255& deskAccName);
- // Attempts to open the desk accessory whose name is deskAccName. Called from
- // TDispatcher::MenuEvent when an Apple menu item is chosen, and the item has a
- // negative command number.
-
- virtual void PollEvent(Boolean allowApplicationToSleep);
- // Polls for events/commands and processes them.
-
- virtual Boolean PollToolboxEvent(Boolean allowApplicationToSleep);
- // Polls for events calling Idle before waitNextEvent if there are no events
- // pending and the application is allowed to go to sleep
- // (kAllowApplicationToSleep), calls HandleEvent with the event, if there is one.
- // and then idles if necessary.
-
- void Run();
- // call MainEventLoop
-
- virtual void UpdateAllWindows();
- // Process all update events in the queue.
-
- virtual Boolean InModalState();
- // Returns true if the front window is modal.
-
- short GetMainEventMask();
- // Retrieve the current main event mask.
-
- short SetMainEventMask(short newMask);
- // Set the main event mask and return the old one.
-
- //------------------------------------------------------------------------------------
- // Target and Cohandlers
- //------------------------------------------------------------------------------------
-
- virtual void InstallCohandler(TEventHandler* aCohandler,
- Boolean addIt);
- // Used to add (addIt = true) or delete (addIt = false) a cohandler to/ from the
- // global list of cohandlers
-
- virtual TWindow* GetFrontWindow();
- // Returns the window object reference for the frontmost application window
- // (whether active or not).
- // Returns NULL if the FrontWindow window is not a window object.
-
- virtual TWindow* GetActiveWindow(Boolean floatersAreOkay);
- // Returns the window object reference for the active application window.
- // Returns NULL if the FrontWindow window is not a window object.
-
- void SetTarget(TEventHandler* newTarget);
- // Sets the current target (the head of the target chain) for the application.
-
- TEventHandler* GetTarget();
- // Returns the current target
-
-
- //------------------------------------------------------------------------------------
- // Finder Requests
- //------------------------------------------------------------------------------------
-
- // virtual Boolean CanOpenDocument(CommandNumber itsCommandNumber, TFile* aFile);
- // Simulates the filtering done by Std File; this is only called when opening/
- // printing documents from the finder; when using Std File, Std File does the
- // filtering.
-
- // virtual void HandleFinderRequest();
- // If the AppleEvents Manager is not required or present: Gets the info from the
- // finder about what files to open/ print and opens/ prints them.
-
-
- //------------------------------------------------------------------------------------
- // Opening and Printing Documents
- //------------------------------------------------------------------------------------
-
- virtual TDocument* FindDocument(TFile* aFile);
- // Given a TFile, if that document is already opened, returns the TDocument.
- // Otherwise returns NULL.
-
- // virtual Boolean ChooseDocument(CommandNumber itsCommandNumber, TList** aFileList);
- // Call this to make a Std File Get call; returns true is user selected a file.
-
- // virtual TDocument* DoMakeDocument(CommandNumber itsCommandNumber, TFile* itsFile);
- // Must be overridden. Based on itsCommandNumber create a document object of the
- // appropriate kind. If itsFile <> NULL it is attached to the document
-
- virtual TFile* DoMakeFile(CommandNumber itsCommandNumber);
- // Default behavior is to return an instance of TFile. May be overridden to create
- // a file of your own special type.
-
- // virtual CommandNumber KindOfDocument(CommandNumber itsCommandNumber, TFile* itsFile);
- // Given a command number and a specification of the file, return the command number to
- // pass to DoMakeDocument that indicates the type of document to make; Default is
- // to return itsCommandNumber. If you have multiple document types, a good convention
- // is to return the command numbers assigned to create new documents of each kind.
- // aFile will be NULL if we are creating a brand new document, rather than opening
- // an existing document.
-
- // virtual TDocument* OpenNew(CommandNumber itsCommandNumber);
- // Called when the application is opened (itsCommandNumber = cFinderNew), or when NEW
- // is chosen from menu (itsCommandNumber = cNew). If you do not want to create a new
- // document when the user opens the application, override this and do nothing if
- // itsCommandNumber = cFinderNew. Returns the document that was opened.
-
- // virtual TDocument* OpenOld(CommandNumber itsOpenCommand, TList* aFileList);
- // Called when opening an existing document from finder (itsCommandNumber =
- // cFinderOpen) or if OPEN is chosen from menu (itsCommandNumber = cOpen).
- // It can also handle stationery.
-
- // virtual void PrintDocuments(CommandNumber itsCommandNumber, TList* aFileList);
- // Called to print the documents specified from the finder. The list of files may
- // have come from a 'pdoc' AppleEvent or from HandleFinderRequest
-
- // virtual void GetStandardFileParameters(CommandNumber itsCommandNumber,
- // ProcPtr& fileFilter,
- // TypeListHandle& typeList,
- // short& dlgID,
- // CPoint& where,
- // ProcPtr& dlgHook,
- // ProcPtr& modalFilter,
- // Ptr& activeList,
- // ProcPtr& activateProc,
- // StandardFileReply* reply,
- // void*& yourDataPtr);
- // Called to return all the parameters that should be passed to SFPGetFile or
- // CustomGetFile, and CanOpenDocument; Defaults to:
- // dlgID = getDlgID or sfGetDialogID;
- // where = (100, 100) or (-1, -1);
- // fileFilter = NULL;
- // dlgHook = NULL;
- // modalFilter = gStandardFileFilter;
- // activeList := NULL;
- // activateProc := NULL;
- // yourDataPtr := NULL;
-
- // virtual void GetFileTypeList(CommandNumber itsCommandNumber,
- // TypeListHandle& typeList);
- // Return an valid handle to a list of file types supported by your application.
- // and the number of types in the list. The default is to allocate enough space
- // for fMainFileType. Called by ChooseDocument to determine the types of files
- // to display. If no type is specified then all types are displayed.
-
-
- //------------------------------------------------------------------------------------
- // Termination
- //------------------------------------------------------------------------------------
-
- virtual void Close();
- // Called when the user chooses Quit from the menu, and tries to save all the open
- // documents. If all succeed the application terminates. Signals Failure with
- // error = noErr and message = messageCancelled if user cancels
-
-
- //------------------------------------------------------------------------------------
- // Hierarchy
- //------------------------------------------------------------------------------------
-
- virtual void AddDocument(TDocument* aNewDocument);
- // Add another document to my list of documents, and make it the current one
-
- virtual void AddWindow(TWindow* aWindow);
- // Add the window to the free-window list
-
- virtual void DeleteDocument(TDocument* docToDelete);
- // Delete a document from my list of documents
-
- virtual void DeleteWindow(TWindow* windowToDelete);
- // Delete a window from my list of free windows
-
-
- //------------------------------------------------------------------------------------
- // Window Manager Windows
- //------------------------------------------------------------------------------------
-
- // Removed for 3.5
- // virtual void SelectToolboxWindow(WindowRef windowToSelect);
- // // "Selects" windowToSelect by calling the toolbox routine SelectWindow. When any
- // // window is selected, it goes through here. We never call SelectWindow directly.
-
- virtual WindowRef NewToolboxWindow(Ptr storage, short rsrcId,
- Boolean& isResizable,
- Boolean& isClosable);
- // Get a Window Manger window resource whose resource id is rsrId. Return
- // isResizable and isClosable based upon the 'WIND' resource.
-
- virtual TWindow* WMgrToWindow(WindowRef aWMgrWindow);
- // Returns the window object that represents the given Window Manager window, or
- // NULL if there is no window object.
-
-
- //------------------------------------------------------------------------------------
- // Idle Events
- //------------------------------------------------------------------------------------
-
- virtual long GetWaitTicks(Boolean allowApplicationToSleep);
- // Compute the "wait ticks" to be passed to GetEvent
-
- virtual void Idle(IdlePhase phase);
- // Parcels out idle time to the DoIdle method in the target and cohandler chains
- // of TEvtHandlers. If your application needs to do something at idle time then
- // override DoIdle instead of this method.
-
-
- //------------------------------------------------------------------------------------
- // Cursor and Help
- //------------------------------------------------------------------------------------
-
- virtual RgnHandle GetSleepRegion();
- // Return the "sleep region" to be passed to GetEvent
-
- virtual void GetDefaultCursorRegion(CPoint globalMouse, RgnHandle cursorRegion);
- // Computes the cursor region for the case where no window has claimed the cursor
-
- virtual void InstallHelpMenuItems();
- // Override this method to install your help menu item(s). Use
- // gMenuBarManager->AddHelpMenuItem( "^0 Help", kYourHelpCommandNumber );
-
- virtual void GetDefaultHelpRegion(CPoint globalMouse, RgnHandle helpRegion);
- // Computes the help region for the case where no window has claimed the cursor
-
- virtual void GetHelpParameters(ResNumber helpResource,
- short helpIndex,
- short helpState,
- HMMessageRecord& helpMessage,
- CPoint& localQDTip,
- CRect& localQDRect,
- short& balloonVariant);
- // Gets balloon contents from an 'hdlg' resource. Called by TView::GetHelpParameters
-
- virtual void DoSetCursor(CPoint globalMouse, RgnHandle cursorRegion);
- // Sets the cursor to an arrow and computes the region for which it is claimed.
- // Called when no view has set the cursor
-
- virtual void TrackCursor(CPoint globalMouse);
- // Allows windows/views to set the cursor and cursor region via TView::HandleCursor
- // and TView::DoSetCursor. If no region is set, the cursor is set to an arrow and
- // the largest possible default cursor region is calculated.
-
- virtual void HandleCursor(CPoint globalMouse, RgnHandle cursorRegion);
-
- virtual void DoShowHelp(CPoint globalMouse, RgnHandle helpRegion);
- // !!!
-
- virtual void TrackHelp(CPoint globalMouse);
- // !!!
-
- virtual void HandleHelp(CPoint globalMouse, RgnHandle helpRegion);
-
- void InvalidateMouseRegions();
- // Invalidates the cursor and help regions
-
- void InvalidateCursorRgn();
- // Sets the cursor region to the empty region
-
- void InvalidateHelpRgn();
- // Sets the help region to the empty region
-
- virtual Boolean IsCursorRgnInvalid();
- // Returns true if the cursor region needs to be recalculated
-
- virtual Boolean IsHelpRgnInvalid();
- // Returns true if the help region needs to be recalculated
-
-
- //------------------------------------------------------------------------------------
- // Keyboard events
- //------------------------------------------------------------------------------------
-
- virtual void DoKeyEvent(TToolboxEvent* event);
- // Handle keydown events.
-
-
- //------------------------------------------------------------------------------------
- // Menu Events
- //------------------------------------------------------------------------------------
-
- virtual void DoCommandKeyEvent(TToolboxEvent* event);
- // Called when a keyDown event is received and the command key is down.
-
- virtual void MenuEvent(long menuItem);
- // Given a value returned by MenuKey or MenuSelect, figure out the command number
- // that was chosen, have the application create a command object, and post it.
-
- virtual void SetupUndoRedoMenus();
- // Setup the Undo and Redo menu items.
-
- virtual void SetUndoText(CommandNumber id);
- // Called to setup the Undo menu item.
-
- virtual void SetRedoText(CommandNumber id);
- // Called to setup the Redo menu item.
-
- virtual void SetupTheMenus();
- // Initiates the process of enabling & checking menu items.
-
- //------------------------------------------------------------------------------------
- // Opening and Closing Windows
- //------------------------------------------------------------------------------------
-
- virtual void CloseToolboxWindow(WindowRef aWMgrWindow);
- // Called when user closes a window either with a menu item or with a GoAway box.
- // Returns FALSE if user cancels.
- // (Used to signal Failure with error = noErr and message = messageCancelled if user cancels)
-
-
- //------------------------------------------------------------------------------------
- // Command Management
- //------------------------------------------------------------------------------------
-
- virtual TEvent* RetrieveAnEvent(); // override
- // Retrieves a previously posted event/ command from the queue. NULL if there are no
- // queued commands.
-
- void RemoveEvent(TEvent* event);
- // Removes a previously posted event/ command from the queue. There is no error
- // if the event is not in the queue.
-
- virtual void ProcessEvent(TEvent* event);
- // Processes the given event from the queue of event objects. The event may be a
- // Toolbox event or a command object. This method calls the event's Process method.
-
- virtual void PostAnEvent(TEvent* event); // override
- // Called to post an event or command to a queue for later processing. Default is
- // to hand off to fNextHandler
-
- virtual void PostCommand(TCommand* command); // override
- // Called to post a command to the queue for later execution.
-
- //------------------------------------------------------------------------------------
- // Double/Triple Clicks
- //------------------------------------------------------------------------------------
-
- virtual short CountClicks(TToolboxEvent* event, short whereMouseDown);
- // Called by TDispatcher::HandleMouseDown. Returns the number of clicks that can
- // be considered multiple clicks (e.g. if it returns 1 the mouse down should be
- // treated as a single click, or possibly the first click of a multi-click
- // sequence. If it returns 2 the click should be considered a double-click, etc. A
- // click is considered part of a multi-click sequence if the mouse down was within
- // the proper time range of the previous mouse up, and was within the proper
- // number of pixels of the last mouse down. TDispatcher::HandleMouseDown sets
- // theClickCount of its EventInfo record to the result of this function.
- // aPDownEvent is a pointer to the mouse down event. whereMouseDown is the result
- // of FindWindow on the event.
-
- //------------------------------------------------------------------------------------
- // Clipboard support
- //------------------------------------------------------------------------------------
-
- virtual void DoLaunchClipboard();
- // calls gClipboardMgr->Launch
-
- virtual TView* MakeViewForAlienClipboard();
- // Override this to create a view to handle your application's specific data
- // types. Return NULL (the default) to have the clipboard manager create a default
- // view.
-
-
- //------------------------------------------------------------------------------------
- // Command Handlers
- //------------------------------------------------------------------------------------
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber);
- // Handles the application specific menu commands.
-
- virtual void DoSetupMenus();
-
- virtual void AboutToLoseControl(Boolean convertClipboard);
- // Called when about to activate a Desk Accessory, switch out to another
- // application, or Terminate. convertClipboard is generally true, except it will
- // be false if we get a System event that does not require Clipboard conversion
-
- virtual void RegainControl(Boolean checkClipboard);
- // Called when switching in or when leaving a desk accessory
-
- // virtual void DoNew(CommandNumber theCmdNumber);
- // Handles the New menu item.
-
- // virtual void DoOpen(CommandNumber theCmdNumber);
- // Handles the Open menu item.
-
- //------------------------------------------------------------------------------------
- // Error Alerts
- //------------------------------------------------------------------------------------
-
- virtual void Beep(short duration);
- // Call this method when you want to beep at the user. Sound manager users may
- // have to override this method to integrate its functionality in with your
- // application
-
- virtual void ShowError(OSErr error, long message);
- // Calls ErrorAlert to display an error alert.
-
- virtual void SpaceIsLowAlert();
- // Called when space is low, at intervals of kLowSpaceInterval ticks. Displays an
- // alerting informing the user that memory space is low. Override this if you wish
- // to take more appropriate action.
-
- //------------------------------------------------------------------------------------
- // AppleEvent Handling
- //------------------------------------------------------------------------------------
-
- virtual Boolean DoUndoRedo(TCommandHandler* theContext,
- CommandNumber aCommandNumber,
- MScriptableObject* theTarget);
- // Handles the undo choice from the menu. If you want undo/redo to be recordable
- // your DoMenuCommand method should call this on cUndo.
-
- virtual Boolean UndoRedoInContext(TCommandHandler* theContext,
- CommandNumber aCommandNumber);
- // Handles the undo event. TDispatcher will handle this for itself, but if
- // you handle undo/redo in another context you should call this from that object's
- // DoScriptCommand method.
-
- // virtual void DoAEClose(TAppleEvent* message,
- // TAppleEvent* reply);
- // Handles the close event for the application.
-
- #if qAttachable
- virtual Boolean HandleOSAEvent(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Overridden to not give OSA the run AppleEvent.
- #endif
-
- virtual void DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply);
- // Handles object model AppleEvents for the application.
-
- // virtual void DoAECreateElement(TAppleEvent* message,
- // TAppleEvent* reply);
- // Creates a new document. If your application has more than one type of document
- // you'll need to override this method. The default simulates choosing "New" from
- // the file menu.
-
- virtual long CountContainedObjects(DescType desiredType);
- // Counts contained documents and window.
-
- virtual MScriptableObject* GetContainedObject(DescType desiredType,
- DescType selectionForm,
- const CAEDesc& selectionData);
-
- virtual MScriptableObject* GetIndContainedObject(DescType desiredType,
- long index);
- // Returns a contained document or window.
-
- virtual TWindow* GetWindowByIndex(short wIndex);
- // Returns a window by front to back order.
-
- virtual TWindow* GetPaletteByIndex(short index);
- // Returns a palette by front to back order.
-
- virtual TDocument* GetDocumentByIndex(DescType desiredType,
- short wIndex);
- // Returns a document based on its position in the application's fDocumentList.
-
- //------------------------------------------------------------------------------------
- // Scripting Utilities
- //------------------------------------------------------------------------------------
-
-
- virtual Boolean MakeObjectSpecifier(CAEDesc& theObjectSpecifier,
- DescType preferredForm = formName);
- // Creates an object specifier for the application.
-
- virtual Boolean IsDocumentClass(DescType desiredType);
- // If your application supports more than one document class you should override this.
- // This method is then called in place of using (desiredType == cDocument).
-
- virtual void ReportReplyError(CommandNumber fromCmdNum,
- OSErr theError,
- const CStr255& theErrStr);
- // When a reply returned through a TSendAECommand contains an error it is sent
- // through this method for reporting.
-
- //------------------------------------------------------------------------------------
- // Dispatcher Properties
- //------------------------------------------------------------------------------------
-
- virtual void SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty);
- // Sets application properties.
-
- virtual Boolean GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType);
- // Gets application properties.
-
- //------------------------------------------------------------------------------------
- // Miscellaneous
- //------------------------------------------------------------------------------------
-
- virtual void DoMakeDependencySpace();
- // Creates a dependency space for storing dependencies, and stores it in gMacAppDependencies.
-
- // virtual void DoAboutBox();
- // Called to show the "About the App" information
-
- virtual void InvalidateFocus();
- // Called to indicate that a view is unfocused when you don't know which view was focused.
-
- virtual Boolean IsHelpEnabled();
- // Returns true if the Help Manager is present and the user has enabled help
-
- virtual OSErr InteractWithUser(long timeOutInTicks,
- NMRecPtr nmReqPtr,
- AEIdleUPP idleProc);
- // Wrapper for AEInteractWithUser. Virtual bottleneck for the Notification Manager.
- // Don't use this directly -- call MAInteractWithUser instead.
-
- virtual Boolean ActivateBusyCursor(Boolean entering);
- // Called when the busy cursor mechanism should be activated or deactivated.
-
- virtual Boolean AlertFilter(DialogRef theDialog, EventRecord& theEvent,
- short& itemHit);
-
- virtual Boolean AppleEventIdleProc(EventRecord& theEventRecord,
- long& sleepTime,
- RgnHandle& mouseRgn);
- // Called by the default AppleEvent idle proc MacAppAppleEventIdleProc.
- // Provides default idle behavior by handling update and activate events.
-
- virtual Boolean StandardFileFilter(DialogRef theDialog,
- EventRecord& theEvent, short& itemHit, void* yourDataPtr);
- // Called by the default Standard File filter proc MacAppStandardFileFilterProc.
-
- virtual void DoMakeViewServer();
- // instantiates the global view server
-
- virtual void GetApplicationName(CStr255& theName);
- // The default behavior is to return the name supplied by GetAppParms
-
- #if qContainer
- //------------------------------------------------------------------------------------
- // Container Application Support
- //------------------------------------------------------------------------------------
-
- public:
-
- virtual void AddCADocument(TFileBasedDocument* aNewDocument);
- virtual void DeleteCADocument(TFileBasedDocument* docToDelete);
-
- static void FocusAcquiredProc(CADocumentRef aCADocRef, CAFocusType focusType);
- static void FocusLostProc(CADocumentRef aCADocRef, CAFocusType focusType);
- static void WindowActivateHandler(WindowPtr theWindow, Boolean activating);
- static pascal Boolean FrameShapeRequestHandler(CADocumentRef aCADocRef,
- CAFrameRef frameRef,
- RgnHandle aRgn);
- static Boolean AdjustBorderHandler(CADocumentRef aCADocRef,
- CAFrameRef frameRef,
- RgnHandle aRgn);
-
- TList* fCADocumentList; //list of CADocuments
-
- protected:
- CADocumentRef fCurrentDocument;
-
-
- #endif
- };
-
- //----------------------------------------------------------------------------------------
- // TNewDocumentCommand: Tells the application open a new document.
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TFilesCommand: Retreives a list of files from an AppleEvent Abstract class for
- // TODocCommand and TPDocCommand.
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TODocCommand: Accepts a list of file aliases and opens each of them
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TQuitCommand: Tells the application to do its pre-quitting stuff.
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TQuitAppCommand: Tells the application to quit in a recordable manner.
- // Don't issue a TQuitAppCommand to quit the application--issue a
- // TQuitCommand instead.
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TAboutBoxCommand: Tells the application to show its about box.
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TEventRetrieverCommand: Retrieve Events and process them.
- //----------------------------------------------------------------------------------------
-
- class TEventRetrieverCommand : public TCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- TEventRetrieverCommand();
- // Empty constructor to satisfy compiler.
- virtual ~TEventRetrieverCommand();
- // Destructor
-
- void IEventRetrieverCommand(CommandNumber itsCommandNumber);
- // Initialize the EventCommand procedurally.
-
- virtual Boolean NeedsToUnloadAllSegments();
- // Return false since we don't want to unload the segments for every event
-
- virtual void DoIt();
- // Retrieve and process an event
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // Globals defined by this unit
- //----------------------------------------------------------------------------------------
-
- extern TDispatcher* gDispatcher; // the application object
-
- extern Boolean gInitialized; // Set to true at top of TDispatcher::Run()
-
- extern AEAddressDesc gServerAddress; // Address of the AppleEvent Server. Initialized
- // to send to ourselves.
-
- extern Boolean gHasODFocus; //Do we have the standard focus? (We are in control)
- extern Boolean gHasODModalFocus; //Do we have the modal focus?
-
- #endif // __UDISPATCHER__
-